Server-Sent Events implementation for UTCP
The SSE (Server-Sent Events) provider enables one-way streaming communication from servers to clients, making it ideal for real-time updates, notifications, and data feeds that don't require bidirectional communication. This provider is perfect for scenarios where you need to push continuous data updates to clients in real-time.
SSE providers are configured using the following JSON structure:
{ "name": "live_updates_service", "provider_type": "sse", "url": "https://api.example.com/events", "event_type": "message", "reconnect": true, "retry_timeout": 30000, "auth": { "auth_type": "api_key", "api_key": "YOUR_API_KEY", "var_name": "X-API-Key" }, "headers": { "User-Agent": "UTCP Client" }, "body_field": "payload", "header_fields": ["api_version", "client_id"] }
Field | Required | Description |
---|---|---|
name |
Yes | Unique identifier for the provider |
provider_type |
Yes | Must be set to "sse" |
url |
Yes | Full URL to the SSE endpoint |
event_type |
No | The event type to listen for (default: null , listens for all events) |
reconnect |
No | Whether to automatically reconnect if the connection is lost (default: true ) |
retry_timeout |
No | Retry timeout in milliseconds if disconnected (default: 30000 ) |
auth |
No | Authentication configuration (if required) |
headers |
No | Additional HTTP headers to include in the request |
body_field |
No | The name of the single input field to be sent as the request body |
header_fields |
No | List of input fields to be sent as request headers for the initial connection |
SSE providers support the same authentication methods as HTTP providers:
{ "auth": { "auth_type": "api_key", "api_key": "YOUR_API_KEY", "var_name": "X-API-Key" } }
{ "auth": { "auth_type": "bearer", "token": "YOUR_BEARER_TOKEN" } }
{ "auth": { "auth_type": "basic", "username": "your_username", "password": "your_password" } }
SSE follows a text-based protocol where each message consists of one or more lines of text:
event: event_type id: message_id data: {"key": "value"}
In UTCP, the data
field is expected to contain JSON that matches the tool's output schema.
For SSE providers, the tool discovery endpoint should be accessible at /utcp
on the same domain as the API. For example:
https://api.example.com/utcp
Since SSE is primarily for receiving streaming data, tools that use SSE providers typically have simple inputs (to establish the connection) and structured streaming outputs.
{ "name": "market_updates", "provider_type": "sse", "url": "https://markets.example.com/stream", "event_type": "price_update", "reconnect": true, "retry_timeout": 30000, "auth": { "auth_type": "api_key", "api_key": "YOUR_MARKET_API_KEY", "var_name": "X-API-Key" } }
{ "name": "notification_service", "provider_type": "sse", "url": "https://notify.example.com/events", "event_type": "notification", "reconnect": true, "auth": { "auth_type": "bearer", "token": "YOUR_NOTIFICATION_TOKEN" } }
{ "name": "chat_stream", "provider_type": "sse", "url": "https://chat.example.com/stream", "event_type": "message", "reconnect": true, "retry_timeout": 15000, "header_fields": ["room_id", "user_id"] }
© 2024 Universal Tool Calling Protocol. All rights reserved.